<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Category extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
        $this->load->config('layout', TRUE);
		$this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		$this->load->library('security');
		$this->load->library('tank_auth');
		$this->load->library('backyard_view');
        $this->load->library('houseme_view');
        $this->load->library('facebook');
		$this->lang->load('tank_auth');
		$this->lang->load('backyard');
        $this->load->model('post_model');
	}

	function index(){}

    function show(){//show category by category id
        $category_id = $this->uri->segment(3);

        $data = array();
        $data['category_id'] = $category_id;
        $data['category'] = $this->config->item('category', 'layout');
        $category_string = $data['category'][$category_id];
        $offset = $this->config->item('more_photo_offset', 'layout');
        $data['page_next_link'] = '/houseme/get_more_category_photo/'.$offset.'/'.$offset.'/'.$category_id;
        $data['all_post'] = $this->post_model->get_all_post_by_category_string($category_string,0,$offset);
        $data['all_share'] = $this->post_model->get_all_share_by_category_string($category_string,0,$offset);
        $data['all_post'] = array_merge($data['all_post'],$data['all_share']);
        usort($data['all_post'], array('Category','dateSort'));//sort post and topic array by datetime
        //echo "<pre>";print_r($data['all_post']);echo "</pre>";exit;
        $data['login_area'] = $this->load->view('houseme/login_area', '', true);
        $this->load->view('houseme/index', $data);
    }

    function dateSort($a,$b){
        $dateA = strtotime($a['modified_time']);
        $dateB = strtotime($b['modified_time']);
        return (($dateA-$dateB)>0)?-1:1;
    }

}

/* End of file category.php */
/* Location: ./application/controllers/category.php */